VERSION 5.00
Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"
Object = "{F0D2F211-CCB0-11D0-A316-00AA00688B10}#1.0#0"; "MSDATLST.OCX"
Begin VB.Form frmINV120 
   BackColor       =   &H8000000D&
   Caption         =   " INV120"
   ClientHeight    =   4545
   ClientLeft      =   1965
   ClientTop       =   2145
   ClientWidth     =   7815
   ControlBox      =   0   'False
   LinkTopic       =   "Form1"
   ScaleHeight     =   4545
   ScaleWidth      =   7815
   Begin MSAdodcLib.Adodc Adodc2 
      Height          =   375
      Left            =   6105
      Top             =   330
      Visible         =   0   'False
      Width           =   1455
      _ExtentX        =   2566
      _ExtentY        =   661
      ConnectMode     =   0
      CursorLocation  =   3
      IsolationLevel  =   -1
      ConnectionTimeout=   15
      CommandTimeout  =   30
      CursorType      =   3
      LockType        =   3
      CommandType     =   8
      CursorOptions   =   0
      CacheSize       =   50
      MaxRecords      =   0
      BOFAction       =   0
      EOFAction       =   0
      ConnectStringType=   1
      Appearance      =   1
      BackColor       =   -2147483643
      ForeColor       =   -2147483640
      Orientation     =   0
      Enabled         =   -1
      Connect         =   ""
      OLEDBString     =   ""
      OLEDBFile       =   ""
      DataSourceName  =   ""
      OtherAttributes =   ""
      UserName        =   ""
      Password        =   ""
      RecordSource    =   ""
      Caption         =   "Adodc2"
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      _Version        =   393216
   End
   Begin MSAdodcLib.Adodc Adodc1 
      Height          =   315
      Left            =   6165
      Top             =   -30
      Visible         =   0   'False
      Width           =   1380
      _ExtentX        =   2434
      _ExtentY        =   582
      ConnectMode     =   0
      CursorLocation  =   3
      IsolationLevel  =   -1
      ConnectionTimeout=   15
      CommandTimeout  =   30
      CursorType      =   3
      LockType        =   3
      CommandType     =   8
      CursorOptions   =   0
      CacheSize       =   50
      MaxRecords      =   0
      BOFAction       =   0
      EOFAction       =   0
      ConnectStringType=   1
      Appearance      =   1
      BackColor       =   -2147483643
      ForeColor       =   -2147483640
      Orientation     =   0
      Enabled         =   -1
      Connect         =   ""
      OLEDBString     =   ""
      OLEDBFile       =   ""
      DataSourceName  =   ""
      OtherAttributes =   ""
      UserName        =   ""
      Password        =   ""
      RecordSource    =   ""
      Caption         =   "Adodc1"
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      _Version        =   393216
   End
   Begin VB.Frame Frame1 
      BackColor       =   &H00E0E0E0&
      BorderStyle     =   0  'None
      Caption         =   "Frame1"
      Height          =   2040
      Left            =   315
      TabIndex        =   10
      Top             =   1590
      Width           =   7065
      Begin VB.TextBox txtLMLOT 
         Height          =   300
         Left            =   1770
         TabIndex        =   21
         Top             =   570
         Width           =   1308
      End
      Begin VB.TextBox txtLMSTT 
         Height          =   288
         Left            =   1770
         Locked          =   -1  'True
         MultiLine       =   -1  'True
         TabIndex        =   19
         Top             =   1470
         Width           =   1290
      End
      Begin VB.TextBox txtLMITN 
         Enabled         =   0   'False
         Height          =   288
         Left            =   1770
         Locked          =   -1  'True
         TabIndex        =   18
         Top             =   135
         Width           =   1332
      End
      Begin MSDataListLib.DataCombo cboLMITN 
         Bindings        =   "frmINV120.frx":0000
         Height          =   285
         Left            =   3120
         TabIndex        =   15
         Top             =   120
         Width           =   2850
         _ExtentX        =   5027
         _ExtentY        =   556
         _Version        =   393216
         Enabled         =   0   'False
         Locked          =   -1  'True
         ListField       =   "IMITD"
         BoundColumn     =   "IMITN"
         Text            =   ""
      End
      Begin VB.TextBox txtLMEDT 
         Enabled         =   0   'False
         Height          =   288
         Left            =   5415
         Locked          =   -1  'True
         TabIndex        =   14
         Top             =   1020
         Width           =   1308
      End
      Begin VB.TextBox txtLMPDT 
         Enabled         =   0   'False
         Height          =   288
         Left            =   1770
         Locked          =   -1  'True
         TabIndex        =   13
         Top             =   1020
         Width           =   1308
      End
      Begin VB.Label lbl 
         BackStyle       =   0  'Transparent
         Caption         =   "Lot status"
         BeginProperty Font 
            Name            =   "Verdana"
            Size            =   7.5
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H8000000D&
         Height          =   225
         Index           =   3
         Left            =   240
         TabIndex        =   20
         Top             =   1485
         Width           =   1095
      End
      Begin VB.Label Label2 
         BackStyle       =   0  'Transparent
         Caption         =   "Expired date "
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H8000000D&
         Height          =   255
         Left            =   4125
         TabIndex        =   17
         Top             =   1050
         Width           =   1170
      End
      Begin VB.Label Label1 
         BackStyle       =   0  'Transparent
         Caption         =   "Production date :"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H8000000D&
         Height          =   252
         Left            =   240
         TabIndex        =   16
         Top             =   1080
         Width           =   1452
      End
      Begin VB.Label lbl 
         BackStyle       =   0  'Transparent
         Caption         =   "Lot No"
         BeginProperty Font 
            Name            =   "Verdana"
            Size            =   7.5
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H8000000D&
         Height          =   228
         Index           =   5
         Left            =   240
         TabIndex        =   12
         Top             =   600
         Width           =   612
      End
      Begin VB.Label lbl 
         BackStyle       =   0  'Transparent
         Caption         =   "Item"
         BeginProperty Font 
            Name            =   "Verdana"
            Size            =   7.5
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H8000000D&
         Height          =   225
         Index           =   4
         Left            =   240
         TabIndex        =   11
         Top             =   120
         Width           =   495
      End
   End
   Begin VB.CommandButton cmdDelete 
      Caption         =   "&Delete"
      Height          =   372
      Left            =   4860
      TabIndex        =   7
      Top             =   3930
      Width           =   960
   End
   Begin VB.CommandButton cmdAddnew 
      Caption         =   "&New"
      Height          =   372
      Left            =   615
      TabIndex        =   4
      Top             =   3930
      Width           =   996
   End
   Begin VB.CommandButton cmdEdit 
      Caption         =   "&Edit"
      Height          =   372
      Left            =   1695
      TabIndex        =   3
      Top             =   3930
      Width           =   948
   End
   Begin VB.CommandButton cmdSave 
      Caption         =   "&Save"
      Height          =   372
      Left            =   2715
      TabIndex        =   2
      Top             =   3930
      Width           =   984
   End
   Begin VB.CommandButton cmdCancel 
      Caption         =   "&Cancel"
      Height          =   372
      Left            =   3765
      TabIndex        =   1
      Top             =   3930
      Width           =   1032
   End
   Begin VB.CommandButton cmdExit 
      Caption         =   "&Exit"
      Height          =   372
      Left            =   5880
      TabIndex        =   0
      Top             =   3930
      Width           =   1080
   End
   Begin MSDataListLib.DataCombo cboList 
      Bindings        =   "frmINV120.frx":0015
      DataSource      =   "Adodc1"
      Height          =   285
      Left            =   3330
      TabIndex        =   8
      Top             =   960
      Width           =   3090
      _ExtentX        =   5450
      _ExtentY        =   556
      _Version        =   393216
      ListField       =   "LMLOT"
      BoundColumn     =   "LMLOT"
      Text            =   ""
   End
   Begin VB.Label lbl 
      BackStyle       =   0  'Transparent
      Caption         =   "Select Lot Review"
      BeginProperty Font 
         Name            =   "Verdana"
         Size            =   7.5
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H0080FFFF&
      Height          =   225
      Index           =   2
      Left            =   1515
      TabIndex        =   9
      Top             =   975
      Width           =   1650
   End
   Begin VB.Label lbl 
      BackStyle       =   0  'Transparent
      Caption         =   "INV120"
      BeginProperty Font 
         Name            =   "VNI-Present"
         Size            =   18
         Charset         =   0
         Weight          =   700
         Underline       =   -1  'True
         Italic          =   -1  'True
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00E0E0E0&
      Height          =   468
      Index           =   0
      Left            =   36
      TabIndex        =   6
      Top             =   24
      Width           =   1680
   End
   Begin VB.Label lbl 
      BackStyle       =   0  'Transparent
      Caption         =   "Lot Master Mainternent"
      BeginProperty Font 
         Name            =   "Verdana"
         Size            =   16.5
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   -1  'True
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00E0E0E0&
      Height          =   492
      Index           =   1
      Left            =   2040
      TabIndex        =   5
      Top             =   420
      Width           =   5028
   End
End
Attribute VB_Name = "frmINV120"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim OldLMLOT As String
Sub ButtonStatus()
cmdAddnew.Enabled = Not ISEDITING
cmdEdit.Enabled = Not ISEDITING
cmdSave.Enabled = ISEDITING ' And txtIMITN <> ""
cmdDelete.Enabled = Not ISEDITING 'And txtIMITN <> ""
CmdCancel.Enabled = ISEDITING
'txtIMITN.Locked = Not ISADDING ' Lock item code tru truong hop ISADDING=true
'txtDepartment.Enabled = ISEDITING
'cboDepartment.Visible = Not ISADDING
'txtDepartmentID.Visible = ISADDING
End Sub

Private Sub Control(GT As Variant)
    
    txtLMITN.Enabled = GT
    cboLMITN.Enabled = GT
    txtLMLOT.Enabled = GT
    txtLMPDT.Enabled = GT
    txtLMEDT.Enabled = GT
  '  txtLMRID.Enabled = GT
  '  txtLMLDT.Enabled = GT
 '   txtLMSTT.Enabled = GT
      
    txtLMITN.Locked = Not GT
    cboLMITN.Locked = Not GT
    txtLMLOT.Locked = Not GT
    txtLMPDT.Locked = Not GT
    txtLMEDT.Locked = Not GT
  '  txtLMRID.Locked = Not GT
  '  txtLMLDT.Locked = Not GT
  '  txtLMSTT.Locked = Not GT
    
    cboList.Enabled = Not GT
    cboList.Locked = GT
End Sub
Private Sub WriteToScreen(tri As Byte)
If tri = 0 Then 'gan rong
        txtLMITN = ""
        cboLMITN.BoundText = ""
        txtLMLOT = ""
        txtLMPDT = Date
        txtLMEDT = Date
        'txtLMRID = "LM"
        'txtLMLDT = Date
        'txtLMSTT = 0
Else
        Dim TBL As ADODB.Recordset
        Set TBL = New ADODB.Recordset
        'TBL.Open "  Select ILM.*From ILM where  LMITN ='" & cboList.BoundText & "' and LMLOT = '" & cboList.Tag & "'", DBconn, adOpenKeyset, adLockOptimistic, adCmdText
        TBL.Open "  Select ILM.* From ILM where  LMLOT ='" & cboList.BoundText & "'", DBconn, adOpenKeyset, adLockOptimistic, adCmdText
        If TBL.EOF = False Then
            txtLMITN = IIf(IsNull(TBL!lmitn), "", TBL!lmitn)
            cboLMITN.BoundText = IIf(IsNull(TBL!lmitn), "", TBL!lmitn)
            txtLMLOT = IIf(IsNull(TBL!lmlot), "", TBL!lmlot)
            txtLMPDT = IIf(IsNull(TBL!lmPDT), Date, TBL!lmPDT)
            txtLMEDT = IIf(IsNull(TBL!lmEDT), Date, TBL!lmEDT)
         '  txtLMRID = "LM"
          ' txtLMLDT = Date
           'txtLMSTT = 0
        Else
            txtLMITN = ""
            cboLMITN.BoundText = ""
            txtLMLOT = ""
            txtLMPDT = Date
            txtLMEDT = Date
            'txtLMRID = "LM"
            'txtLMLDT = Date
            'txtLMSTT = 0
        End If
        TBL.Close
End If
OldLMLOT = txtLMLOT
End Sub
Private Sub WriteToFile(tri As Byte)
Dim SQLInsert As String
If tri = 0 Then
    SQLInsert = " INSERT INTO ILM " & _
                  "(LMITN,LMLOT,LMPDT,LMEDT,LMSTT,LMRID,LMLDT,LMRCU,LMISU,LMAJU,LMRCW" & _
                  ",LMISW,LMAJW) " & _
                " VALUES " & _
                  "('" & Left(txtLMITN, 15) & "', '" & Left(txtLMLOT, 10) & "' ,'" & Format(CDate(txtLMPDT), "yyyy-mm-dd hh:mm:ss") & _
                  "', '" & Format(CDate(txtLMEDT), "yyyy-mm-dd hh:mm:ss") & "', 0, 'LM'" & _
                  ", '" & Format(Date, "yyyy-mm-dd hh:mm:ss") & "',0,0,0,0,0,0)"
 Else
    SQLInsert = "UPDATE ILM SET LMITN = '" & Left(txtLMITN, 15) & "', LMLOT ='" & Left(txtLMLOT, 10) & "'" & _
                ", LMPDT ='" & Format(CDate(txtLMPDT), "yyyy-mm-dd hh:mm:ss") & "'" & _
                ", LMEDT = '" & Format(CDate(txtLMEDT), "yyyy-mm-dd hh:mm:ss") & "'" & _
                " WHERE LMLOT ='" & OldLMLOT & "'"
End If

Set cmdExecute = New ADODB.Command
Set cmdExecute.ActiveConnection = DBconn
cmdExecute.CommandText = SQLInsert
cmdExecute.Execute

End Sub



Private Sub cboList_Click(Area As Integer)
If Area = 2 Then
    WriteToScreen (1)
End If
End Sub

Private Sub cboLMITN_Click(Area As Integer)
If Area = 2 Then
    txtLMITN = cboLMITN.BoundText
    With Adodc2.Recordset
        .MoveFirst
        Do Until !imitn = cboLMITN.BoundText
            .MoveNext
            If .EOF Then Exit Do
        Loop
        If .EOF = False Then
            If !IMLOT = True Then
                txtLMLOT.Enabled = True
                txtLMLOT.Locked = False
            Else
                MsgBox "This Item haven't got lot."
                txtLMLOT = ""
                txtLMLOT.Enabled = False
                txtLMLOT.Locked = True
            End If
        End If
    End With

End If
End Sub

Private Sub cmdAddnew_Click()
ISADDING = True
ISEDITING = True
WriteToScreen (0)
Control (True)
' Ham Gan tri man hinh
ButtonStatus
txtLMITN.SetFocus

End Sub
Private Sub cmdCancel_Click()
' Gan tri man nhinh
ISADDING = False
ISEDITING = False
Control (False)
ButtonStatus
txtLMITN = cboList.BoundText
WriteToScreen (1)

End Sub

Private Sub cmdDelete_Click()
ISADDING = False
ISEDITING = False
' Ham delete theo Item chon
Dim sql As String
sql = "DELETE FROM ILM WHERE LMITN = '" & txtLMITN & "' and LMLOT = '" & txtLMLOT & "'"

Set cmdExecute = New ADODB.Command
Set cmdExecute.ActiveConnection = DBconn
cmdExecute.CommandText = sql
cmdExecute.Execute
Adodc1.Refresh
WriteToScreen (0)
ButtonStatus

End Sub

Private Sub cmdEdit_Click()
ISEDITING = True
' Ham gan tri man hinh
ISADDING = False
ISEDITING = True
Control (True)
txtLMITN.SetFocus
ButtonStatus

End Sub

Private Sub cmdexit_Click()
Unload frmINV120
End Sub

Private Sub cmdSave_Click()
If ISADDING = False Then
    WriteToFile (1)
Else
    WriteToFile (0)
End If
Adodc1.Refresh
Control (False)
'''''''''''
ISADDING = False
ISEDITING = False

ButtonStatus

End Sub

Private Sub Form_Load()
BIENCHUNG
Adodc1.ConnectionString = ConnectString
Adodc1.ConnectionTimeout = 10
Adodc1.CommandType = adCmdTable
Adodc1.RecordSource = "ILM" 'lote master
Adodc1.Refresh

Adodc2.ConnectionString = ConnectString
Adodc2.ConnectionTimeout = 10
Adodc2.CommandType = adCmdTable
Adodc2.RecordSource = "IIM" 'company profile
Adodc2.Refresh
ISADDING = False
ISEDITING = False
ButtonStatus

End Sub

Private Sub txtLMITN_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
    With Adodc2.Recordset
        .MoveFirst
        Do Until !imitn = txtLMITN
            .MoveNext
            If .EOF Then Exit Do
        Loop
        If .EOF = False Then
            cboLMITN.BoundText = txtLMITN
            cboLMITN_Click (2)
        Else
            cboLMITN.BoundText = ""
            MsgBox "Khong co Item"
            cboLMITN.SetFocus
        End If
    End With
End If
End Sub



Private Sub txtLMLOT_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
    If ValidMaso(OldLMLOT, txtLMLOT, "ILM", " LMLOT='" & txtLMLOT & "'") Then
        MsgBox "This code is already exist"
        txtLMLOT.SetFocus
    Else
        txtLMPDT.SetFocus
    End If
End If
End Sub
